#include "GravityData.h"

namespace binge
{

GravityData::GravityData(void)
{

}

GravityData::~GravityData(void)
{
    objectsGravity.clear();
    objectsJumpSpeed.clear();
    objectsJumpPeak.clear();
    objectsGround.clear();
    objectsStatus.clear();

    objectsXEdgeReflect.clear();
    objectsXWallReflect.clear();
}

void
GravityData::AddObject(int id)
{
    objectsId.push_back(id);
    objectsGravity.push_back(4.f);
    objectsJumpSpeed.push_back(0.1f); // 10%
    objectsJumpPeak.push_back(100.f);
    objectsGround.push_back(0.f);
    objectsStatus.push_back(GRAVITY_FALLING);

    objectsXEdgeReflect.push_back(false);
    objectsXWallReflect.push_back(false);
}

void
GravityData::RemoveObject(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsId.erase(objectsId.begin()+index);
        objectsGravity.erase(objectsGravity.begin()+index);
        objectsJumpSpeed.erase(objectsJumpSpeed.begin()+index);
        objectsJumpPeak.erase(objectsJumpPeak.begin()+index);
        objectsGround.erase(objectsGround.begin()+index);
        objectsStatus.erase(objectsStatus.begin()+index);

        objectsXEdgeReflect.erase(objectsXEdgeReflect.begin()+index);
        objectsXWallReflect.erase(objectsXWallReflect.begin()+index);
    }
}

float
GravityData::GetGravity(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsGravity[index];
    }
    return 4.f; // Default value.
}

void
GravityData::SetGravity(int id, float value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsGravity[index] = value;
    }
}

int
GravityData::GetStatus(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsStatus[index];
    }
    return GRAVITY_FALLING;
}

void
GravityData::SetStatus(int id, int value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsStatus[index] = value;
    }
}

float
GravityData::GetJumpSpeed(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsJumpSpeed[index];
    }
    return 0.1f; // Default value.
}

void
GravityData::SetJumpSpeed(int id, float value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsJumpSpeed[index] = value;
    }
}

float
GravityData::GetJumpPeak(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsJumpPeak[index];
    }
    return 100.f; // Default value.
}

void
GravityData::SetJumpPeak(int id, float value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsJumpPeak[index] = value;
    }
}

float
GravityData::GetGround(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsGround[index];
    }
    return 0.f; // Default value.
}

void
GravityData::SetGround(int id, float value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsGround[index] = value;
    }
}

bool
GravityData::HasXEdgeReflect(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsXEdgeReflect[index];
    }
    return false; // Default value.
}

void
GravityData::SetXEdgeReflect(int id, bool value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsXEdgeReflect[index] = value;
    }
}

bool
GravityData::HasXWallReflect(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsXWallReflect[index];
    }
    return false; // Default value.
}

void
GravityData::SetXWallReflect(int id, bool value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsXWallReflect[index] = value;
    }
}

} // namespace
